package Java9_15;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Scanner;

public class SupermaketTest {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        try {
            ObjectInputStream oi = new ObjectInputStream(new FileInputStream("D:\\rubbish\\9.15Work1.txt"));
            Supermaket s = (Supermaket) oi.readObject();
            oi.close();
            while (true) {
                System.out.println("1.开卡  2.查询  9.退出系统");
                int i = in.nextInt();
                if (i == 1) {
                    Vip vip = new Vip();
                    System.out.println("输入卡号");
                    vip.setId(in.next());
                    System.out.println("输入积分");
                    vip.setJifen(in.nextInt());
                    boolean isRegister = s.register(vip);
                    System.out.println(isRegister ? "开卡成功" : "卡号重复");
                } else if (i == 2) {
                        System.out.println("查询结果如下");
                        s.show();

                } else if (i == 9) {
                    try {
                        ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream("D:\\rubbish\\9.15Work1.txt"));
                        oo.writeObject(s);
                        oo.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return;
                }
            }
        } catch (Exception e) {
            try {
                ObjectOutputStream oo = new ObjectOutputStream(new FileOutputStream("D:\\rubbish\\9.15Work1.txt"));
                oo.writeObject(new Supermaket("万达", "110", "安徽"));
                oo.close();
            } catch (Exception ee) {
                ee.printStackTrace();
            }
        }
    }
}
